<div>
    <script>
    $(document).ready(function(){
        $("#btn_accept").click(function(){
	    debugger;
            $('#btn_accept').attr('disabled',true);
	    
	    //validar comodines
	    if(valida_willcard() == true)
		select_all();
		else
		return;
        });
	
	$("#group_").change(function(){
	   
	});
	
	$("#addGroupBtn").click(function(){
	    //remove class active
	    $(".side-nav li").removeClass("active");
	    //add class active to selected element
	    //$(this).addClass('active');
	    $("#groupsOption").addClass('active');
	    $("#content_container").html('');
	    $("#content_container").html("");
	    var data_ajax={
		    type: 'POST',
		    url: "groups",
		    data: { },
		    success: function( data ) {
						$("#content_container").html(data);
					      },
		    error: function(data){$("#content_container").html(data);},
		    dataType: 'json'
		    };
	    $.ajax(data_ajax);
	});
    });
    
    function acceptButton() {
	$('#btn_accept').attr('disabled',true);
	    
	    //validar comodines
	    if(valida_willcard() == true)
		select_all();
		else
		return;
    }
    function set(id, name)
    {
	$("#group_").val(id);
	$("#spanName").html(name);
	$("#games tbody tr").remove();
	var data_ajax={
		     type: 'POST',
		     url: "<?php echo base_url(); ?>user/load_game_gpo",
		     data: { gpo: $("#group_").val()},
		     success: function( data ) {

						 var row;
						 var match = 1;
						 var local;
						 var empate;
						 var visita;
						 var partidoWilcard1 = "";
						 var partidoWilcard2 = "";
						 var wilcard1 = "";
						 var wilcard2 = "";
						 var numberPartidoWilcard1 = "";
						 var numberPartidoWilcard2 = "";
						 $.each(data, function(k,v){
						     $.each(v, function(i,j){
							 local = j['result'] == 1 ? "checked" : "";
							 empate = j['result'] == 0 ? "checked" : "";
							 visita = j['result'] == 2 ? "checked" : "";
							 if (j['willcard'] != null) {
							     if (wilcard1 == ""){
								     partidoWilcard1 = j['idGame'];
								     wilcard1 = j['willcard'];
								     numberPartidoWilcard1 = match;
								 }
								 else{
								     partidoWilcard2 = j['idGame'];
								     wilcard2 = j['willcard'];
								     numberPartidoWilcard2 = match;
								 }
							 }
							 
							 row = "<tr>";
							 row += "<td style=\"text-align: center; padding-top: 10px;\"><strong>" + match + "</strong></td>";
							 row += "<td style=\"text-align: center\"><input type=\"radio\" id=\"" + j['idGame'] + "\" name=\"" + j['idGame'] + "\" value=\"1\" " + local + "></td>";
							 row += "<td width=\"25\" style=\"cursor: pointer;\" onclick=\"Estadisticas('" + j['localName'] +"')\"><img src=\"<?echo base_url()?>assets/img/escudos/" + j['localImage'] +" \" width=\"25\" height=\"25\"></td>";
							 row += "<td style=\"cursor: pointer;\" onclick=\"Estadisticas('" + j['localName'] + "')\">" + j['localName'] + "</td>";
							 row += "<td style=\"text-align: center\"><input type=\"radio\" id=\"" + j['idGame'] + "\" name=\"" + j['idGame'] + "\" value=\"0\" " + empate + "></td>";
							 row += "<td style=\"cursor: pointer;\" onclick=\"Estadisticas('" + j['visitName'] + "')\">" + j['visitName'] + "</td>";
							 row += "<td width=\"25\" style=\"cursor: pointer;\" onclick=\"Estadisticas('" + j['visitName'] +"')\"><img src=\"<?echo base_url()?>assets/img/escudos/" + j['visitImage'] +" \" width=\"25\" height=\"25\"></td>";
							 row += "<td style=\"text-align: center\"><input type=\"radio\" id=\"" + j['idGame'] + "\" name=\"" + j['idGame'] + "\" value=\"2\" " + visita + "></td>";
							 row += "</tr>";
							 $("#games tbody").append(row);
							 match++;
						     });
						 });
						 
						 if (partidoWilcard1 != "") {
						     $("#wildcard_1").val(partidoWilcard1);
						     $("#wildcard_1_res").val(wilcard1);
						     $("#spanName_wc1").html(numberPartidoWilcard1);
						     $("#spanName_wcr1").html((wilcard1 == 0 ? "Empate" : (wilcard1 == 1 ? "Local" : "Visitante")));
						 }else
						 {
						     $("#wildcard_1").val(0);
						     $("#wildcard_1_res").val(0);
						     $("#spanName_wc1").html("");
						     $("#spanName_wcr1").html("");
						 }
						 if (partidoWilcard2 != "") {
						     $("#wildcard_2").val(partidoWilcard2);
						     $("#wildcard_2_res").val(wilcard2);
						     $("#spanName_wc2").html(numberPartidoWilcard2);
						     $("#spanName_wcr2").html((wilcard2 == 0 ? "Empate" : (wilcard2 == 1 ? "Local" : "Visitante")));
						 }else
						 {
						     $("#wildcard_2").val(0);
						     $("#wildcard_2_res").val(0);
						     $("#spanName_wc2").html("");
						     $("#spanName_wcr2").html("");
						 }
					       },
		     error: function(){
			 alert("Error");
			 $('#waiting').fadeOut('slow');
			 },
		     dataType: 'json'
		     };
		     $.ajax(data_ajax);
    }
    
    function set_wcr1(value)
    {
	switch (value) {
	    case 0:
		$("#wildcard_1_res").val(0);
		$("#spanName_wcr1").html("Empate");
		break;
	    case 1:
		$("#wildcard_1_res").val(1);
		$("#spanName_wcr1").html("Local");
		break;
	    case 2:
		$("#wildcard_1_res").val(2);
		$("#spanName_wcr1").html("Visitante");
		break;
	}
    }
    
    function set_game1(id, name) {
	$("#wildcard_1").val(id);
	$("#spanName_wc1").html(name);
    }
    
    function set_wcr2(value)
    {
	switch (value) {
	    case 0:
		$("#wildcard_2_res").val(0);
		$("#spanName_wcr2").html("Empate");
		break;
	    case 1:
		$("#wildcard_2_res").val(1);
		$("#spanName_wcr2").html("Local");
		break;
	    case 2:
		$("#wildcard_2_res").val(2);
		$("#spanName_wcr2").html("Visitante");
		break;
	}
    }
    
    function set_game2(id, name) {
	$("#wildcard_2").val(id);
	$("#spanName_wc2").html(name);
    }
    
    function valida_willcard()
    {
	if($('#wildcard_1').val() == $('#wildcard_2').val())
	{
	    $('#error_willcard').show();
	    setTimeout("$('#error_willcard').hide('slow');", 4000);
	    $('#btn_accept').removeAttr('disabled');
	    return false;
	}
	else
	{
	    $('#error_willcard').hide();
	    return true;
	}
    }

    function select_all()
    {
	$("#operation_result").hide();
	
	var allgpo = true;
	if ($('#repetir').length)
	    if ($('#repetir:checked').val() != "on")
		allgpo = false;
	
        var sites=[];
        var names=[];
	var willcard=[];
        var  is_checked=0;
        $('#games :checked').each(function() {
                         sites.push($(this).val());
                         names.push($(this).attr('name'));
                         is_checked ++;
                 });
        
	willcard.push($('#wildcard_1').val());
	willcard.push($('#wildcard_1_res').val());
	willcard.push($('#wildcard_2').val());
	willcard.push($('#wildcard_2_res').val());
         
	$("#waiting").fadeIn('slow');   
        var data_ajax={
                        type: 'POST',
                        url: "<?php echo base_url(); ?>user/register_game",
                        data: { xsites: sites, xnames: names, xwillcard: willcard, gpoId: $("#group_").val(), all: allgpo },
                        success: function( data ) {
                                                    if(data != 0)
                                                    {	
                                                       Message_operation("operation_result","succesfull");
						       $("#waiting").fadeOut('slow'); 
                                                    }
                                                    else
                                                    {
                                                       Message_operation("operation_result","error");
						       $("#waiting").fadeOut('slow'); 
                                                    }
                                                  },
                        error: function(){log("Error"); $("#waiting").fadeOut('slow'); },
                        dataType: 'json'
                        };
			$.ajax(data_ajax);
    }
    
    function log(str_log)
    {
        try {
                console.log(str_log + "\n");
        } catch(e) {

        }
    }
    
    function Message_operation(idDiv, type)
    {
        var div = '#'+idDiv;
        
        if(type == "error")
        {
           $(div).removeClass("alert-success").addClass("alert-danger");
           $("#operation_result_msj").html("<i class=\"fa fa-ban\"></i> Ocurrio un error, intente nuevamente la operación.");
	   $(div).show();
        }
        else
        {
	    
           $(div).removeClass("alert-danger").addClass("alert-success");
           $("#operation_result_msj").html("<i class=\"fa fa-check\"></i> La operación se registro correctamente.");
	   $(div).show();
        }
	
	$('#btn_accept').removeAttr('disabled');
    }
    
    function Estadisticas(name)
    {
	$('#teamNameDiv').html(name);
	$('#welcomeMsj').hide();
	$('#graphicsGRF').show();
	$('#cantPartidos').html("Partidos Jugados 0");
	$('#ganados').text("0");$('#empatados').text("0");$('#perdidos').text("0");
	$('#ganadosLoc').text("0");$('#empatadosLoc').text("0");$('#perdidosLoc').text("0");
	$('#ganadosVis').text("0");$('#empatadosVis').text("0");$('#perdidosVis').text("0");
	$('#barG').css('width', '0%');$('#barE').css('width', '0%');$('#barP').css('width', '0%');
	
	$("#waiting").fadeIn('slow'); 
	var data_ajax={
                        type: 'POST',
                        url: "<?php echo base_url(); ?>user/graphics",
                        data: { team: name, est: 'L'},
                        success: function( data ) {
                                                    if(data != 0 && data != -1)
                                                    {
							var partidos 	= 0;
							var ganados 	= 0;
							var perdidos 	= 0;
							var empatados 	= 0;
							
							$.each(data, function(k,v)
                                                                {
								    switch(k)
								    {
									case "partidos":
									    $('#cantPartidos').html("Partidos Jugados " + v);
									    partidos = v;
									    break;
									
									case "ganados":
									    $('#ganados').text(v);
									    ganados = v;
									    break;
									
									case "empatados":
									    $('#empatados').text(v);
									    empatados = v;
									    break;
									
									case "perdidos":
									    $('#perdidos').text(v);
									    perdidos = v;
									    break;
									
									case "ganadosLoc":
									    $('#ganadosLoc').text(v);
									    break;
									
									case "empatadosLoc":
									    $('#empatadosLoc').text(v);
									    break;
									
									case "perdidosLoc":
									    $('#perdidosLoc').text(v);
									    break;
									
									case "ganadosVis":
									    $('#ganadosVis').text(v);
									    break;
									
									case "empatadosVis":
									    $('#empatadosVis').text(v);
									    break;
									
									case "perdidosVis":
									    $('#perdidosVis').text(v);
									    break;
									
								    }
								    
								});
						       
						       //Calcular barra
						       //Ganados
						       if( ganados > 0 )
						       {
							    var p = (ganados * 100 ) / partidos;
							    $('#barG').css('width', p +'%');
						       }
						       else
						       {
							    $('#barG').css('width', '0%');
						       }
						       
						       if( empatados > 0)
						       {
							    var p = (empatados * 100 ) / partidos;
							    $('#barE').css('width', p +'%');
						       }
						       else
						       {
							    $('#barE').css('width', '0%');
						       }
						       
						       if( perdidos > 0)
						       {
							    var p = (perdidos * 100 ) / partidos;
							    $('#barP').css('width', p +'%');
						       }
						       else
						       {
							    $('#barP').css('width', '0%');
						       }
						       //-----------------------------------------
						    }
                                                    else
                                                    {
                                                       //alert("Error");
						       log("Error");
                                                    }
						    
						    $("#waiting").fadeOut('slow'); 
                                                  },
                        error: function(){log("Error"); $("#waiting").fadeOut('slow'); },
                        dataType: 'json'
                        };
			$.ajax(data_ajax);
    }
    
    </script>
    <div class="row">
	<div class="col-md-6">
	    <section class="widget">
		<header>
		    <h4>
			<i class="fa fa-users"></i>
			Grupos 
			<small>
			    y Jugadas
			</small>
		    </h4>
		</header>
		<div class="body text-align-center">
		    <div class="alert alert-danger" style="display: none" id="error_willcard">
			<p>
			<i class="fa fa-ban"></i> 
			
			<strong>Error!! </strong>
			Los comodines no pueden ser usados para el mismo partido.
			</p>
		    </div>
		    
		    <?php
		    if($this->session->userdata('logged_in') && $data != 0)
		    {
			$disabled = count($data[0]) <= 1 ? "disabled" : "";
			
			if($enabled == true)
			{
			    //no se puede jugar
			    $date = explode('-',$date);
			    echo '
				<div class="alert alert-danger">
				    <p>
				    <i class="fa fa-ban"></i> 
				    No tenes tiempo de jugar o modificar tu jugada, el plazo fue hasta el día '.$date[2].'-'.$date[1].'-'.$date[0].' a las  18:00 horas, espera a la próxima fecha. 
				    <p>
				</div>
				';
			}
			else
			{
			    //si se puede jugar
			    $date = explode('-',$date);
			    echo '
				<div class="alert alert-info">
				    <p>
				    <i class="fa fa-info-circle"></i> 
				    Podes jugar o modificar tu jugada hasta el día '.$date[2].'-'.$date[1].'-'.$date[0].' a las 18:00 horas. 
				    <p>
				</div>
				';
			}
			?>
			
			<div class="alert" style="display: none" id="operation_result">
			    <p id="operation_result_msj"></p>
			</div>
			    
			<div class="control-group">
			    <table>
				<tr>
				    <td><label for="article-category" class="control-label" style="padding-right: 15px;">Grupo:</td>
				    <td>
					<div class="controls form-group">
					    <select id="group_" class="input-large" <?php echo $disabled; ?> data-style="btn-warning" class="selectpicker" style="display: none;">
						<?php
						    foreach($data[0] as $value)
						    {
							echo '<option value="'.$value['id'].'">"'.$value['name'].'"</option>';
						    }
						?>
					    </select>
					    <div class="btn-group bootstrap-select" style="padding-top: 15px;">
						<button class="btn dropdown-toggle clearfix btn-success" data-toggle="dropdown" id="group_">
						    <span class="filter-option" id="spanName"><?= $data[0][0]['name']; ?></span>&nbsp;<i class="fa fa-caret-down"></i>
						</button>
						    <ul class="dropdown-menu" role="menu" style="max-height: 323px; overflow-y: auto; min-height: 60px;">
							<?php
							    foreach($data[0] as $value)
							    {
								echo '<li rel="'.$value['id'].'" onClick="set('.$value['id'].',\''.$value['name'].'\');"><a tabindex="1" href="#" class="">'.$value['name'].'</a></li>';
							    }
							?>
						    </ul>
					    </div>
					</div>
				    </td>
				    <td>
					<label style="padding-left: 20px;">
					    Repetir jugada para todos mis grupos <input type="checkbox" id="repetir" >
					</label>
				    </td>
				</tr>
			    </table>
			    </label>
			</div>
			
		    <?php
		    }
		    else
		    {
			echo "<div class=\"alert alert-error\">
				No tienes grupos asociados aun.
			    </div>
			    ";
			echo '<button id="addGroupBtn" style="margin-left: 15px;" type="button" class="btn btn-success">
				Crear un grupo e invitar a mis amigos
			      </button>';
		    }
		    ?>
		    
		    <?php
			if($this->session->userdata('logged_in') && $data != 0)
			{
			    ?>
			    <table id="games" class="table table-striped">
				<thead>
				    <tr>
					<th></th>
					<th colspan="3" style="text-align: center">Local</th>
					<th style="text-align: center">Empate</th>
					<th colspan="3" style="text-align: center">Visitante</th>
				    </tr>
				</thead>
				<tbody>
				<?php
			
				    $partido = 0;
				    $comodinFecha1 = -1;
				    $comodinFecha1Resultado = -1;
				    $comodinFecha2 = -1;
				    $comodinFecha2Resultado = -1;
				    
				    foreach($data[1] as $value)
				    {
					$partido++;
					if($value['willcard'] != null)
					{
					    if($comodinFecha1 == -1)
					    {
						$comodinFecha1 = $value['idGame'];
						$comodinFecha1Resultado = $value['willcard'];
					    }
					    else
					    {
						$comodinFecha2 = $value['idGame'];
						$comodinFecha2Resultado = $value['willcard'];
					    }
					}
					
					echo '<tr>';
					switch($value['result'])
					{
					    //Empate
					    case 0:
						echo '<td style="text-align: center; padding-top: 10px;"><strong>'.$partido.'</strong></td>';
						echo '<td style="text-align: center">'.form_radio($value['idGame'], 1, FALSE).'</td>';
						echo '<td width="25" style="cursor: pointer;" onclick="Estadisticas(\''.$value['localName'].'\')"><img src="'.base_url().'assets/img/escudos/'.$value['localImage'].'" width="25" height="25"></td>';
						echo '<td style="cursor: pointer;" onclick="Estadisticas(\''.$value['localName'].'\')">'.$value['localName'].'</td>';
						echo '<td style="text-align: center">'.form_radio($value['idGame'], 0, TRUE).'</td>';
						echo '<td style="cursor: pointer;" onclick="Estadisticas(\''.$value['visitName'].'\')">'.$value['visitName'].'</td>';
						echo '<td width="25" style="cursor: pointer;" onclick="Estadisticas(\''.$value['visitName'].'\')"><img src="'.base_url().'assets/img/escudos/'.$value['visitImage'].'" width="25" height="25"></td>';
						echo '<td style="text-align: center">'.form_radio($value['idGame'], 2, FALSE).'</td>';
						break;
					    //Local
					    case 1:
						echo '<td style="text-align: center; padding-top: 10px;"><strong>'.$partido.'</strong></td>';
						echo '<td style="text-align: center">'.form_radio($value['idGame'], 1, TRUE).'</td>';
						echo '<td width="25" style="cursor: pointer;" onclick="Estadisticas(\''.$value['localName'].'\')"><img src="'.base_url().'assets/img/escudos/'.$value['localImage'].'" width="25" height="25"></td>';
						echo '<td style="cursor: pointer;" onclick="Estadisticas(\''.$value['localName'].'\')">'.$value['localName'].'</td>';
						echo '<td style="text-align: center">'.form_radio($value['idGame'], 0, FALSE).'</td>';
						echo '<td style="cursor: pointer;" onclick="Estadisticas(\''.$value['visitName'].'\')">'.$value['visitName'].'</td>';
						echo '<td width="25" style="cursor: pointer;" onclick="Estadisticas(\''.$value['visitName'].'\')"><img src="'.base_url().'assets/img/escudos/'.$value['visitImage'].'" width="25" height="25"></td>';
						echo '<td style="text-align: center">'.form_radio($value['idGame'], 2, FALSE).'</td>';
						break;
					    //Visitante
					    case 2:
						echo '<td style="text-align: center; padding-top: 10px;"><strong>'.$partido.'</strong></td>';
						echo '<td style="text-align: center">'.form_radio($value['idGame'], 1, FALSE).'</td>';
						echo '<td width="25" style="cursor: pointer;" onclick="Estadisticas(\''.$value['localName'].'\')"><img src="'.base_url().'assets/img/escudos/'.$value['localImage'].'" width="25" height="25"></td>';
						echo '<td style="cursor: pointer;" onclick="Estadisticas(\''.$value['localName'].'\')">'.$value['localName'].'</td>';
						echo '<td style="text-align: center">'.form_radio($value['idGame'], 0, FALSE).'</td>';
						echo '<td style="cursor: pointer;" onclick="Estadisticas(\''.$value['visitName'].'\')">'.$value['visitName'].'</td>';
						echo '<td width="25" style="cursor: pointer;" onclick="Estadisticas(\''.$value['visitName'].'\')"><img src="'.base_url().'assets/img/escudos/'.$value['visitImage'].'" width="25" height="25"></td>';
						echo '<td style="text-align: center">'.form_radio($value['idGame'], 2, TRUE).'</td>';
						break;
					    //Default -> Empate
					    default:
						echo '<td style="text-align: center; padding-top: 10px;"><strong>'.$partido.'</strong></td>';
						echo '<td style="text-align: center">'.form_radio($value['idGame'], 1, FALSE).'</td>';
						echo '<td width="25" style="cursor: pointer;" onclick="Estadisticas(\''.$value['localName'].'\')"><img src="'.base_url().'assets/img/escudos/'.$value['localImage'].'" width="25" height="25"></td>';
						echo '<td style="cursor: pointer;" onclick="Estadisticas(\''.$value['localName'].'\')">'.$value['localName'].'</td>';
						echo '<td style="text-align: center">'.form_radio($value['idGame'], 0, TRUE).'</td>';
						echo '<td style="cursor: pointer;" onclick="Estadisticas(\''.$value['visitName'].'\')">'.$value['visitName'].'</td>';
						echo '<td width="25" style="cursor: pointer;" onclick="Estadisticas(\''.$value['visitName'].'\')"><img src="'.base_url().'assets/img/escudos/'.$value['visitImage'].'" width="25" height="25"></td>';
						echo '<td style="text-align: center">'.form_radio($value['idGame'], 2, FALSE).'</td>';
						break;
					}
					echo '</tr>';
				    }
		    ?>
			</tbody>
			</table>
			
			<!-- Comodines -->
			<table class="table table-striped">
			    <thead>
				<tr>
				    <th style="text-align: center; width: 50%;" colspan="2">Comodín 1</th>
				    <th style="text-align: center; width: 50%;" colspan="2">Comodín 2</th>
				</tr>
			    </thead>
			    <tbody>
				<tr>
				    <td style="text-align: center; width: 20%;">Partido</td>
				    <td style="text-align: center; width: 30%;">Resultado</td>
				    <td style="text-align: center; width: 20%;">Partido</td>
				    <td style="text-align: center; width: 30%;">Resultado</td>
				</tr>
				<tr>
				    <td style="text-align: center;">
					<!---->
					<div class="control-group" style="margin-top: -15px;">
					    
					    <div class="controls form-group">
						<select id="wildcard_1" class="input-large" <?php echo $disabled; ?> data-style="btn-warning" class="selectpicker" style="display: none;">
						    <?php
							$partido = 0;
							$partidoSelect = "";
							foreach($data[1] as $value)
							{
							    $partido++;
							    if($value['idGame'] == $comodinFecha1)
								{
								    echo '<option value="'.$value['idGame'].'" selected>'.$partido.'</option>';
								    $partidoSelect = $partido;
								}
								else
								{
								    echo '<option value="'.$value['idGame'].'">'.$partido.'</option>';
								}
							}
						    ?>
						</select>
						<div class="btn-group bootstrap-select" style="padding-top: 15px;">
						    <button class="btn dropdown-toggle clearfix btn-info" data-toggle="dropdown" id="group_">
							<span class="filter-option" id="spanName_wc1"><?= $partidoSelect ?></span>&nbsp;<i class="fa fa-caret-down"></i>
						    </button>
							<ul class="dropdown-menu" role="menu" style="max-height: 323px; overflow-y: auto; min-height: 60px;">
							    <?php
								$partido = 0;
								foreach($data[1] as $value)
								{
								    $partido++;
								    echo '<li rel="'.$value['idGame'].'" onClick="set_game1('.$value['idGame'].',\''.$partido.'\');"><a tabindex="1" href="#" class="">'.$partido.'</a></li>';
								}
							    ?>
							</ul>
						</div>
					    </div>  
					</div>
					<!---->
				    </td>
				    <td style="text-align: center;">
					<!--- ---->
					<div class="control-group" style="margin-top: -15px;">
					    
					    <div class="controls form-group">
						<?php
						    $name = 0;
						    switch($comodinFecha1Resultado)
						    {
							case 1: $name = "Local"; break;
							case 0: $name = "Empate"; break;
							case 2: $name = "Visitante"; break;
						    }
						?>
						<select id="wildcard_1_res" class="input-large" <?php echo $disabled; ?> data-style="btn-warning" class="selectpicker" style="display: none;">
						    <option value="1" <?= ($comodinFecha1Resultado == 1 ? "selected": "" );?> >Local</option>
						    <option value="0" <?= ($comodinFecha1Resultado == 0 ? "selected": "" );?> >Empate</option>
						    <option value="2" <?= ($comodinFecha1Resultado == 2 ? "selected": "" );?> >Visita</option>
						</select>
						<div class="btn-group bootstrap-select" style="padding-top: 15px;">
						    <button class="btn dropdown-toggle clearfix btn-info" data-toggle="dropdown" id="group_">
							<span class="filter-option" id="spanName_wcr1"><?= $name ?></span>&nbsp;<i class="fa fa-caret-down"></i>
						    </button>
							<ul class="dropdown-menu" role="menu" style="max-height: 323px; overflow-y: auto; min-height: 60px;">
							    <?php
								echo '<li rel="1" onClick="set_wcr1(1);"><a tabindex="1" href="#" class="">Local</a></li>';
								echo '<li rel="0" onClick="set_wcr1(0);"><a tabindex="1" href="#" class="">Empate</a></li>';
								echo '<li rel="2" onClick="set_wcr1(2);"><a tabindex="1" href="#" class="">Visitante</a></li>';
							    ?>
							</ul>
						</div>
					    </div>  
					</div>					
					<!--- ---->
				    </td>
				    <td style="text-align: center;">
					<!---->
					<div class="control-group" style="margin-top: -15px;">
					    
					    <div class="controls form-group">
						<select id="wildcard_2" class="input-large" <?php echo $disabled; ?> data-style="btn-warning" class="selectpicker" style="display: none;">
						    <?php
							$partido = 0;
							$partidoSelect = "";
							foreach($data[1] as $value)
							{
							    $partido++;
							    if($value['idGame'] == $comodinFecha2)
								{
								    echo '<option value="'.$value['idGame'].'" selected>'.$partido.'</option>';
								    $partidoSelect = $partido;
								}
								else
								{
								    echo '<option value="'.$value['idGame'].'">'.$partido.'</option>';
								}
							}
						    ?>
						</select>
						<div class="btn-group bootstrap-select" style="padding-top: 15px;">
						    <button class="btn dropdown-toggle clearfix btn-info" data-toggle="dropdown" id="group_">
							<span class="filter-option" id="spanName_wc2"><?= $partidoSelect ?></span>&nbsp;<i class="fa fa-caret-down"></i>
						    </button>
							<ul class="dropdown-menu" role="menu" style="max-height: 323px; overflow-y: auto; min-height: 60px;">
							    <?php
								$partido = 0;
								foreach($data[1] as $value)
								{
								    $partido++;
								    echo '<li rel="'.$value['idGame'].'" onClick="set_game2('.$value['idGame'].',\''.$partido.'\');"><a tabindex="1" href="#" class="">'.$partido.'</a></li>';
								}
							    ?>
							</ul>
						</div>
					    </div>  
					</div>
					<!---->
				    </td>
				    <td style="text-align: center;">
					<!--- ---->
					<div class="control-group" style="margin-top: -15px;">
					    
					    <div class="controls form-group">
						<?php
						    $name = 0;
						    switch($comodinFecha2Resultado)
						    {
							case 1: $name = "Local"; break;
							case 0: $name = "Empate"; break;
							case 2: $name = "Visitante"; break;
						    }
						?>
						<select id="wildcard_2_res" class="input-large" <?php echo $disabled; ?> data-style="btn-warning" class="selectpicker" style="display: none;">
						    <option value="1" <?= ($comodinFecha2Resultado == 1 ? "selected": "" );?> >Local</option>
						    <option value="0" <?= ($comodinFecha2Resultado == 0 ? "selected": "" );?> >Empate</option>
						    <option value="2" <?= ($comodinFecha2Resultado == 2 ? "selected": "" );?> >Visita</option>
						</select>
						<div class="btn-group bootstrap-select" style="padding-top: 15px;">
						    <button class="btn dropdown-toggle clearfix btn-info" data-toggle="dropdown" id="group_">
							<span class="filter-option" id="spanName_wcr2"><?= $name ?></span>&nbsp;<i class="fa fa-caret-down"></i>
						    </button>
							<ul class="dropdown-menu" role="menu" style="max-height: 323px; overflow-y: auto; min-height: 60px;">
							    <?php
								echo '<li rel="1" onClick="set_wcr2(1);"><a tabindex="1" href="#" class="">Local</a></li>';
								echo '<li rel="0" onClick="set_wcr2(0);"><a tabindex="1" href="#" class="">Empate</a></li>';
								echo '<li rel="2" onClick="set_wcr2(2);"><a tabindex="1" href="#" class="">Visitante</a></li>';
							    ?>
							</ul>
						</div>
					    </div>  
					</div>					
					<!--- ---->
				    </td>
				</tr>
			    </tbody>
			    
			</table>
			
			<br>
			<?php
			    echo anchor('/user/dashboard','Cancelar','class="btn btn-danger"').'&nbsp&nbsp';
			    if($enabled == true)
				{
				    echo '<a id="" class="btn btn-success" disabled="false">Aceptar</a>';      
				}
				else
				{
				    echo '<a id="btn_accept" onClick="acceptButton()" class="btn btn-success">Aceptar</a>';
				}
			}
			?>
		</div>
	    </section>
	</div>
    
	<?php
	if($this->session->userdata('logged_in') && $data != 0)
	{
	    ?>
	<div class="col-md-6">
	    <section class="widget">
		<header>
		    <h4>
			<i class="fa fa-bar-chart-o"></i>
			Estadísticas para:
			<small id="teamNameDiv">
			    --
			</small>
		    </h4>
		</header>
		<div class="body text-align-center" id="staticsDiv">
		    <span id="welcomeMsj">Has click en el escudo o nombre de un equipo para ver sus estadisticas.</span>
		    <div id="graphicsGRF" style="display: none">
		    <div id="mainGraphics" style="text-align: left; font-size: 11px;">
			<!-- Cantidad de partidos -->
			<div class="alert alert-info" style="text-align: center">
			    <strong id="cantPartidos"></strong>
			</div>
			<!-- Ganados -->
			Partidos ganados <span class="badge badge-success" id="ganados">0</span>
			<div class="progress progress-success" style="height: auto;">
                            <div class="progress-bar progress-bar-success" style="width: 0%; height: 45px;" id="barG"></div>
                        </div>
			
			<!-- Empatados -->
			Partidos empatados <span class="badge badge-info" id="empatados">0</span>
			<div class="progress progress-info" style="height: auto;">
                            <div class="progress-bar progress-bar-info" style="width: 0%; height: 45px;" id="barE"></div>
                        </div>
			
			<!-- Perdidos -->
			Partidos perdidos <span class="badge badge-danger" id="perdidos">0</span>
			<div class="progress progress-danger" style="height: auto;">
                            <div class="progress-bar progress-bar-danger" style="width: 0%; height: 45px;" id="barP"></div>
                        </div>
			
		    </div>
		    
		    <table style="width: 100%">
			<tr>
			    <td style="width: 50%">
				<div id="localGraphics" style="font-size: 11px;">
				    <span class="label">Local</span><br><br>
					Ganados <span class="badge badge-success" id="ganadosLoc">-</span><br><br>
					Empatados <span class="badge badge-info" id="empatadosLoc">-</span><br><br>
					Perdidos <span class="badge badge-danger" id="perdidosLoc">-</span>
				</div>
			    </td>
			    <td style="width: 50%">
				<div id="visitaGraphics" style="font-size: 11px;">
				    <span class="label">Visitante</span><br><br>
					Ganados <span class="badge badge-success" id="ganadosVis">-</span><br><br>
					Empatados <span class="badge badge-info" id="empatadosVis">-</span><br><br>
					Perdidos <span class="badge badge-danger" id="perdidosVis">-</span>
				</div>
			    </td>
			</tr>
		    </table>
		    </div>
		</div>
	    </section>
	</div>
	    <?php
	}
	?>
    </div>
    
</div>

<div class="modal hide fade" id="modal_estadisticas">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h3 id="title_date"></h3>
    </div>
    <div class="modal-body">
	<br>
        <table id="table_results" style="height: 300px; width: 100%">
	    <thead>
		<tr>
		    <td rowspan="2" style="alignment-adjust: central; text-align: center; width: 50%">
			<div id="mainGraphics" style="text-align: left; font-size: 11px;">
			    <!-- Cantidad de partidos -->
			    <div class="alert alert-info" style="text-align: center">
				<strong id="cantPartidos"></strong>
			    </div>
			    <!-- Ganados -->
			    Partidos ganados <span class="badge badge-success" id="ganados">x</span>
			    <div class="progress progress-success" style="height: auto;">
				<div class="bar" style="width: 0%; height: 45px;" id="barG"></div>
			    </div>
			    
			    <!-- Empatados -->
			    Partidos empatados <span class="badge badge-info" id="empatados">x</span>
			    <div class="progress progress-info" style="height: auto;">
				<div class="bar" style="width: 0%; height: 45px;" id="barE"></div>
			    </div>
			    
			    <!-- Perdidos -->
			    Partidos perdidos <span class="badge badge-important" id="perdidos">x</span>
			    <div class="progress progress-danger" style="height: auto;">
				<div class="bar" style="width: 0%; height: 45px;" id="barP"></div>
			    </div>
			    
			</div>
		    </td>
		    <td style="height: 150px; alignment-adjust: central; text-align: right;">
			<div id="localGraphics" style="font-size: 11px;">
			    <span class="label">Local</span><br><br>
				Ganados <span class="badge badge-success" id="ganadosLoc">2</span><br><br>
				Empatados <span class="badge badge-info" id="empatadosLoc">2</span><br><br>
				Perdidos <span class="badge badge-important" id="perdidosLoc">2</span>
			</div>
		    </td>
		</tr>
		<tr>
		    <td style="height: 150px; alignment-adjust: central; text-align: right;">
			<div id="visitaGraphics" style="font-size: 11px;">
			    <span class="label">Visitante</span><br><br>
				Ganados <span class="badge badge-success" id="ganadosVis">x</span><br><br>
				Empatados <span class="badge badge-info" id="empatadosVis">x</span><br><br>
				Perdidos <span class="badge badge-important" id="perdidosVis">x</span><br><br>
			</div>
		    </td>
		</tr>
	    </thead>
        </table>
        <div id="error_msj" style="color: red"></div>
    </div>
    <div class="modal-footer">
        <strong><i style="font-size: 15px;">Estadísticas</i></strong>
    </div>
</div>